Repository navigation
csnode: validate CompressedRegion before decompressing (remote crash during sync) - #4
Merged
Merged
Conversation
Compressor::decompress() trusts the region it is given. In
Node::getBlockReply that region, and its binary size, are read straight from
a peer's packet (operator>>(IDataStream&, CompressedRegion&)), so one packet
can take down a syncing node:
- binarySize is an arbitrary size_t. bytes.resize(binarySize) throws
std::length_error/std::bad_alloc, nothing on the transport thread catches
it, and the node terminates.
- An empty region (data() == nullptr, size() == 0) takes the "not compressed"
branch with size = 0 - 1 and reads from nullptr + 1: SIGSEGV.
Reject both before touching memory and return T{}, as decompress() already
does when LZ4 fails. Callers already handle an empty result ("No pools
found").
- An empty region is rejected.
- A compressed region is rejected when binarySize exceeds INT_MAX (LZ4 works
with int sizes) or 256 x the compressed size. LZ4 cannot expand data more
than 255:1, so no region produced by compress() is affected.
Tests (tests/csnode/compressor_tests.cpp):
- Compressor.RejectsBinarySizeLz4CannotProduce: before the fix it throws
std::bad_alloc.
- Compressor.RejectsEmptyRegion: before the fix it crashes with SIGSEGV.
nodetests: 112/112 pass.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: remote crash of a syncing node
Compressor::decompress()trusts the region it is given. InNode::getBlockReplyboth the region and itsbinarySizecome straight from a peer's packet (operator>>(IDataStream&, CompressedRegion&)), so a single packet can take down a syncing node:binarySizebytes.resize()throwsstd::bad_alloc/length_error, nothing on the transport thread catches it, and the process terminatessize = 0 - 1and reads fromnullptr + 1: SIGSEGVFix (
csnode/include/csnode/compressor.hpp, +18)Both cases are rejected before touching memory, returning
T{}, which is whatdecompress()already does when LZ4 fails. Callers already handle an empty result ("No pools found").binarySizeexceedsINT_MAX(LZ4 works withintsizes) or 256 x the compressed size. LZ4 cannot expand data more than 255:1, so no region produced bycompress()is affected.Tests (
tests/csnode/compressor_tests.cpp)Compressor.RejectsBinarySizeLz4CannotProducestd::bad_allocCompressor.RejectsEmptyRegionnodetestsUpstream
A single commit that applies as is to CREDITSCOM/node, where
compressor.hppis identical. It does not depend on the fork's CI.🤖 Generated with Claude Code